package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_DOU_LUO_DA_LU_TEAM_APPLY,desc = "申请加入队伍")
public class DouLuoDaLuApplyJoinTeamCmd extends AbstractCommand {

    long teamId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuJoinTeamReqMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuJoinTeamReqMsg.parseFrom(packet.getBytes());
        teamId = reqMsg.getTeamId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if ((ret = DouLuoDaLuMgr.canEntryActivity(player)) != 0) return;

        //v4.3 活动期间可操作
        //ret = DouLuoDaLuMgr.activityInCreateTeamPeriod();
        //if(ret != 0){
        //    return;
        //}
        DouLuoDaLuProto.DouLuoDaLuJoinTeamCrossReqMsg.Builder crossReq = DouLuoDaLuProto.DouLuoDaLuJoinTeamCrossReqMsg.newBuilder();
        crossReq.setActivityId(DouLuoDaLuMgr.getActivityInfo().getActivityId());
        crossReq.setTeamId(teamId);
        player.sendUnionActivityGroupPacket(Protocol.C_DOU_LUO_DA_LU_TEAM_APPLY, crossReq, crossReq.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            DouLuoDaLuProto.DouLuoDaLuJoinTeamRespMsg.Builder respMsg = DouLuoDaLuProto.DouLuoDaLuJoinTeamRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_TEAM_APPLY, respMsg);
        }
    }
}
